package com.cch.cooperation.api.auth.service;

import com.cch.cooperation.api.auth.dto.UserDeviceDTO;
import org.redisson.api.RedissonClient;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.concurrent.TimeUnit;

@Service
public class UserDeviceServiceImpl {

    @Resource
    private RedissonClient redissonClient;

    private static final String DEVICE_KEY = "USER:DEVICE:";

    public void set(UserDeviceDTO req) {
        redissonClient.getBucket(DEVICE_KEY + req.getUserId()).set(req, 10, TimeUnit.DAYS);
    }

    public UserDeviceDTO get(String userId) {
        return redissonClient.<UserDeviceDTO>getBucket(DEVICE_KEY + userId).get();
    }
}
